﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AutoMapper;

using Happy.Archetype;
using Happy.Application.Domain.CommonModel.TreeLike;
using Happy.Domain.CommonModel.TreeLike;
using Happy.Navigation.Domain;
using Happy.Navigation.Domain.Menus;
using Happy.Navigation.Query.Menus;
using Happy.Navigation.Domain.Services;

namespace Happy.Navigation.Application.Menus
{
    [ApplicationService]
    public sealed class MenuService : TreeNodeService<Menu, MenuView, INavigationUnitOfWork, INavigationNodePathRepairer>
    {
        protected override Menu CreateAggregate(MenuView viewModel)
        {
            var aggregate = base.CreateAggregate(viewModel);

            return Mapper.Map(viewModel, aggregate);
        }

        protected override Menu NewAggregate(MenuView viewModel, Menu parent)
        {
            return new Menu(Guid.NewGuid(), parent);
        }

        protected override Menu NewAggregate(MenuView viewModel)
        {
            return new Menu(Guid.NewGuid());
        }

        protected override void UpdateAggregate(Menu aggregate, MenuView viewModel)
        {
            base.UpdateAggregate(aggregate, viewModel);

            Mapper.Map(viewModel, aggregate);
        }
    }
}
